package club.dmyang.controller;

import club.dmyang.service.AutheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by brss on 2018/6/28.
 */
@Controller
public class MainController {

    @Autowired
    private AutheService autheService;


    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("name","我是海宝宝~~~");
        return "testpage";
    }
    @RequestMapping("/index")
    public String index(){
        return "index";
    }
    @RequestMapping("/logout")
    public String logout(){
        autheService.logout();
        return "loginpage";
    }
    @RequestMapping("/noAuth")
    public String noAuth(){
        return "noAuth";
    }
    @RequestMapping("/query")
    public String query(){
        return "operation/query";
    }
    @RequestMapping("/del")
    public String del(){
        return "operation/del";
    }
    @RequestMapping("/add")
    public String add(){
        return "operation/add";
    }
    @RequestMapping("/update")
    public String update(){
        return "operation/update";
    }
    @RequestMapping("/loginpage")
    public String loginPage(){
        return "loginpage";
    }

    @RequestMapping("/login")
    public String login(String name,String password,Model model){
        if (autheService.login(name, password)){
            return "index";//登录成功
        }else {
            model.addAttribute("msg","用户或密码不正确！");
            return "loginpage";
        }
    }

}
